const Answer = require('../models/answer');
const sequelize =require('../config/database')

exports.getAnswers = async () => {
  const answers = await Answer.findAll({
    attributes: [
      [sequelize.fn('COUNT', sequelize.col('*')), 'total'],
      [sequelize.fn('AVG', sequelize.col('learn')), 'avglearn'],
      [sequelize.fn('STDDEV', sequelize.col('learn')), 'stdDevlearn'],
      [sequelize.fn('AVG', sequelize.col('experience')), 'avgexperience'],
      [sequelize.fn('STDDEV', sequelize.col('experience')), 'stdDevexperience'],
      [sequelize.fn('AVG', sequelize.col('health')), 'avghealth'],
      [sequelize.fn('STDDEV', sequelize.col('health')), 'stdDevhealth'],
      [sequelize.fn('AVG', sequelize.col('burnout')), 'avgburnout'],
      [sequelize.fn('STDDEV', sequelize.col('burnout')), 'stdDevburnout'],
      // [sequelize.fn('AVG', sequelize.col('anxious')), 'avganxious'],
      // [sequelize.fn('STDDEV', sequelize.col('anxious')), 'stdDevanxious'],
      [sequelize.fn('AVG', sequelize.col('pressure')), 'avgpressure'],
      [sequelize.fn('STDDEV', sequelize.col('pressure')), 'stdDevpressure'],
      [sequelize.fn('AVG', sequelize.col('ability')), 'avgability'],
      [sequelize.fn('STDDEV', sequelize.col('ability')), 'stdDevability'],
      // [sequelize.fn('AVG', sequelize.col('ba')), 'avgba'],
      // [sequelize.fn('STDDEV', sequelize.col('ba')), 'stdDevba'],
      [sequelize.fn('AVG', sequelize.col('pa')), 'avgpa'],
      [sequelize.fn('STDDEV', sequelize.col('pa')), 'stdDevpa'],
      [sequelize.fn('AVG', sequelize.col('ea')), 'avgea'],
      [sequelize.fn('STDDEV', sequelize.col('ea')), 'stdDevea'],
      [sequelize.fn('AVG', sequelize.col('sa')), 'avgsa'],
      [sequelize.fn('STDDEV', sequelize.col('sa')), 'stdDevsa'],
      [sequelize.fn('AVG', sequelize.col('pb')), 'avgpb'],
      [sequelize.fn('STDDEV', sequelize.col('pb')), 'stdDevpb'],
      [sequelize.fn('AVG', sequelize.col('influence')), 'avginfluence'],
      [sequelize.fn('STDDEV', sequelize.col('influence')), 'stdDevinfluence'],
      [sequelize.fn('AVG', sequelize.col('oi')), 'avgoi'],
      [sequelize.fn('STDDEV', sequelize.col('oi')), 'stdDevoi'],
      [sequelize.fn('AVG', sequelize.col('pi')), 'avgpi'],
      [sequelize.fn('STDDEV', sequelize.col('pi')), 'stdDevpi'],
      [sequelize.fn('AVG', sequelize.col('si')), 'avgsi'],
      [sequelize.fn('STDDEV', sequelize.col('si')), 'stdDevsi']
      // 添加其他字段的平均值和标准差
      // ...
    ],
  })
  return answers;
};

exports.createAnswer = async (answerData) => {
  const answer = await Answer.create(answerData);
  return answer;
};